<template>
  <div class="user-info">
    <!-- 个人信息 -->
    <el-form label-width="220px">
      <!-- 工号 入职时间 -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="工号">
            <el-input v-model="userInfo.workNumber" class="inputW" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="入职时间">
            <el-date-picker v-model="userInfo.timeOfEntry" style="width: 300px" type="date" class="inputW" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 姓名 部门 -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="姓名">
            <el-input v-model="userInfo.username" class="inputW" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="部门">
            <el-input v-model="userInfo.departmentName" class="inputW" disabled />
          </el-form-item>
        </el-col>
      </el-row>
      <!--手机 聘用形式  -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="手机">
            <el-input v-model="userInfo.mobile" style="width: 300px" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="聘用形式">
            <!-- v-model要有一个值, 能够和option的value值匹配
              数据->视图上下拉菜单默认选中
            -->
            <el-select v-model="userInfo.formOfEmployment" class="inputW">
              <el-option v-for="item in EmployeeEnum.hireType" :key="item.id" :label="item.value" :value="item.id" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 员工照片 -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="员工头像">
            <!-- 扩展知识点:
              v-model 作用: 实现双向数据绑定
              v-model 本质:
              给当前标签:value属性, v-model右侧的变量赋予给value属性 (数据 -> 视图)
              给当前标签绑定@input事件, 并且把收到的值直接赋予给
              v-model右侧的变量 (视图 -> 数据)

              和.sync差不多, 但是.sync可以写多个, vue2.6中组件
              v-model只能写一个(vue3可以写多个v-model)
              其实都是为了让子组件快速给父组件变量赋值
             -->
            <upload-img v-model="userInfo.staffPhoto" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 保存个人信息 -->
      <el-row class="inline-info" type="flex" justify="center">
        <el-col :span="12">
          <el-button type="primary" @click="saveUser">保存更新</el-button>
          <el-button @click="$router.back()">返回</el-button>

        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import EmployeeEnum from '@/api/constant'

export default {
  data() {
    return {
      userInfo: {
        // 员工信息对象
        workNumber: '',
        timeOfEntry: '',
        username: '',
        departmentName: '',
        mobile: '',
        formOfEmployment: '',
        staffPhoto: ''
      },
      EmployeeEnum // 聘用形式枚举对象(.hireType是在上面标签取出的数组循环)
    }
  },
  methods: {
    // 保存->员工信息
    saveUser() {
      this.$emit('updateUserInfoEV', this.userInfo)
      // 如果下一步不清空表单, 可以不用拷贝
    }
  }
}
</script>

<style scoped lang="scss">
.user-info {
  padding-top: 20px;
}
</style>
